package mementopattern;

public class Main {
    public static void main(String[] args) {
        // 创建发起人，并创建备忘录
        Originator originator = new Originator();
        originator.setState("State1");
        Memento memento = originator.createMemento();
        //保存状态
        Caretaker caretaker = new Caretaker();
        caretaker.addMemento(memento);
        // 修改状态
        originator.setState("State2");
        System.out.println("Current state: " + originator.getState());
        // 恢复状态
        memento = caretaker.getMemento();
        originator.restoreMemento(memento);
        System.out.println("Current state: " + originator.getState());
    }
}
